﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UToggleGroup :MonoBehaviour {

    public Action<UToggle> OnValueChanged;
    void Awake()
    {
        UToggle[] toggles = this.transform.GetComponentsInChildren<UToggle>();
        foreach (var item in toggles)
        {
            item.OnValueChanged += OnToggleChanged;
        }
        if (toggles.Length > 0)
        {
            toggles[0].isOn = true;
        }
    }

    private void OnToggleChanged(UToggle arg1, bool arg2)
    {
        UToggle[] toggles = this.transform.GetComponentsInChildren<UToggle>();
        foreach (var item in toggles)
        {
            item.isOn = false;
        }
        arg1.isOn = true;
        if (OnValueChanged != null)
        {
            Debug.Log("click");
            OnValueChanged(arg1);
        }
    }
}
